# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        黄周云  
# Name:         test14_5
# Description:  例14.5
# Author:       ASUS
# Date:         2019/4/17
#-------------------------------------------------------------------------------


import json
class Product:
    def __init__(self,d):
        self.__dict__ = d
f = open('files/product.json','r')
jsonStr = f.read()
my1 = json.loads(jsonStr,object_hook=Product)
print('name','=',my1.name)
print('price','=',my1.price)
print('count','=',my1.count)
print("-----------------")
#定义回调函数，返回一个类的对象
def json2Product(d):
    return Product(d)
my2 = json.loads(jsonStr,object_hook=json2Product)
print('name','=',my2.name)
print('price','=',my2.price)
print('count','=',my2.count)
f.close()
